version 14.2
set more off
set matsize 11000

***********************************************************************************************************************
* THIS ROUTINE GENERATES TABLE A.V OF WASEEM (2020) ROLE OF WITHHOLDING ...
***********************************************************************************************************************

/* TABLE */

#d				;
matrix 			input table=(0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0);
#d				cr

/* ALL FIRMS */

use						"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
keep					if fy>1996 & fy<=2003
keep                	if business_sts=="1" | business_sts=="2"
g						ind=real(substr(item_cd,1,4))
drop					if ind<1600
drop					if ind>=2500 & ind<2800
g						quarter=qofd(taxperiod)
qui						sum quarter
replace					quarter=quarter-r(min)+1
qui						sum quarter
local					qmax=r(max)
g						filed=0
forvalues				q=1/`qmax' {
replace					filed=1 if quarter==`q'
}
bys						regno quarter:g first=_n==1
bys						regno:egen nqreturn=sum(first)
keep					if nqreturn==`qmax'
drop					period
g						period=mofd(taxperiod)
qui						sum period
replace					period=period-r(min)+1
g						treat=business_sts=="1"
g						after=(fy>=1999)
g						treat_after=treat*after						
g						lnsales=log(domsale_ag)
qui						tab fy,g(fydum)
local 					i=1
forvalues 				y=1997/2003 {
g 							treat_`y'=treat*fydum`i'
							local i=`i'+1
}
qui						tab period, g(pdum)

/* BASELINE SPECIFICATION */

local					i=2
local					j=1
qui						areg lnsales pdum2-pdum84 treat treat_after, absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
matrix					table[6,`j']=e(N)
local					j=`j'+1
qui						areg lnsales pdum2-pdum84 treat treat_1998 treat_after, absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
local					i=`i'+2
matrix					table[`i',`j']=_b[treat_1998]
matrix					table[`i'+1,`j']=_se[treat_1998]
matrix					table[6,`j']=e(N)
local					j=`j'+1

/* DROPPING TOP FIRMS */

bys						regno:egen sigmasale_t=sum(domsale_ag) if fy<1998 
bys						regno:egen sigmasale=min(sigmasale_t)
qui						sum sigmasale if treat==1,d
g						exclude=0 
replace					exclude=1 if sigmasale>r(p99) & treat==1
qui						sum sigmasale if treat==0,d
replace					exclude=1 if sigmasale>r(p99) & treat==0
local					i=2
qui						areg lnsales pdum2-pdum84 treat treat_after if exclude==0, absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
matrix					table[6,`j']=e(N)
local					j=`j'+1
qui						areg lnsales pdum2-pdum84 treat treat_1998 treat_after if exclude==0, absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
local					i=`i'+2
matrix					table[`i',`j']=_b[treat_1998]
matrix					table[`i'+1,`j']=_se[treat_1998]
matrix					table[6,`j']=e(N)
local					j=`j'+1
drop					exclude
qui						sum sigmasale if treat==1,d
g						exclude=0 
replace					exclude=1 if sigmasale>r(p95) & treat==1
qui						sum sigmasale if treat==0,d
replace					exclude=1 if sigmasale>r(p95) & treat==0
local					i=2
qui						areg lnsales pdum2-pdum84 treat treat_after if exclude==0, absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
matrix					table[6,`j']=e(N)
local					j=`j'+1
qui						areg lnsales pdum2-pdum84 treat treat_1998 treat_after if exclude==0, absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
local					i=`i'+2
matrix					table[`i',`j']=_b[treat_1998]
matrix					table[`i'+1,`j']=_se[treat_1998]
matrix					table[6,`j']=e(N)
local					j=`j'+1
drop					exclude
qui						sum sigmasale if treat==1,d
g						exclude=0 
replace					exclude=1 if sigmasale>r(p90) & treat==1
qui						sum sigmasale if treat==0,d
replace					exclude=1 if sigmasale>r(p90) & treat==0
local					i=2
qui						areg lnsales pdum2-pdum84 treat treat_after if exclude==0, absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
matrix					table[6,`j']=e(N)
local					j=`j'+1
qui						areg lnsales pdum2-pdum84 treat treat_1998 treat_after if exclude==0, absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
local					i=`i'+2
matrix					table[`i',`j']=_b[treat_1998]
matrix					table[`i'+1,`j']=_se[treat_1998]
matrix					table[6,`j']=e(N)
local					j=`j'+1

*-----------------------------------------------------
* PLACEBO
*-----------------------------------------------------

use						"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
keep					if fy>2003 & fy<=2010
keep                	if business_sts=="1" | business_sts=="2"
g						ind=real(substr(item_cd,1,4))
drop					if ind<1600
drop					if ind>=2500 & ind<2800
g						quarter=qofd(taxperiod)
qui						sum quarter
replace					quarter=quarter-r(min)+1
qui						sum quarter
local					qmax=r(max)
g						filed=0
forvalues				q=1/`qmax' {
replace					filed=1 if quarter==`q'
}
bys						regno quarter:g first=_n==1
bys						regno:egen nqreturn=sum(first)
keep					if nqreturn==`qmax'
drop					period
g						period=mofd(taxperiod)
qui						sum period
replace					period=period-r(min)+1
g						treat=business_sts=="1"
g						after=(fy>=2006)
g						treat_after=treat*after						
g						lnsales=log(domsale_ag)
qui						tab fy,g(fydum)
local 					i=1
forvalues 				y=2004/2010 {
g 							treat_`y'=treat*fydum`i'
							local i=`i'+1
}
qui						tab period, g(pdum)

/* BASELINE SPECIFICATION */

local					i=8
local					j=1
qui						areg lnsales pdum2-pdum84 treat treat_after, absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
matrix					table[10,`j']=e(N)

/* DROPPING TOP FIRMS */

bys						regno:egen sigmasale_t=sum(domsale_ag) if fy<1998
bys						regno:egen sigmasale=min(sigmasale_t)
qui						sum sigmasale if treat==1,d
g						exclude=0 
replace					exclude=1 if sigmasale>r(p99) & treat==1
qui						sum sigmasale if treat==0,d
replace					exclude=1 if sigmasale>r(p99) & treat==0
local					i=8
local					j=`j'+2
qui						areg lnsales pdum2-pdum84 treat treat_after if exclude==0, absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
matrix					table[10,`j']=e(N)
local					j=`j'+2
drop					exclude
qui						sum sigmasale if treat==1,d
g						exclude=0 
replace					exclude=1 if sigmasale>r(p95) & treat==1
qui						sum sigmasale if treat==0,d
replace					exclude=1 if sigmasale>r(p95) & treat==0
local					i=8
qui						areg lnsales pdum2-pdum84 treat treat_after if exclude==0, absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
matrix					table[10,`j']=e(N)
local					j=`j'+2
drop					exclude
qui						sum sigmasale if treat==1,d
g						exclude=0 
replace					exclude=1 if sigmasale>r(p90) & treat==1
qui						sum sigmasale if treat==0,d
replace					exclude=1 if sigmasale>r(p90) & treat==0
local					i=8
qui						areg lnsales pdum2-pdum84 treat treat_after if exclude==0, absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
matrix					table[10,`j']=e(N)


/* FORMATTING TABLE */

svmat 			table
keep			tab*
drop			table9-table12
keep			if _n<=10
g				c11=""
replace			c11="\underline{A: 1997-2003}" in 1
replace			c11="$\mbox{\emph{Manuf}} \times \mbox{\emph{Post}}$" in 2
replace			c11="$\mbox{\emph{Manuf}} \times  1998$" in 4
replace			c11="Observations" in 6
replace			c11="\underline{B: 2004-2010}" in 7
replace			c11="$\mbox{\emph{Manuf}} \times \mbox{\emph{Post}}$" in 8
replace			c11="Observations" in 10
forvalues 		c=1/8 {
g				c`c'=string(table`c',"%9.3f")
}
foreach			r in 3 5 9 {
forvalues		c=1/8 {
replace			c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues		c=1/8 {
replace			c`c'=string(table`c',"%15.0fc") in 6
replace			c`c'=string(table`c',"%15.0fc") in 10
}
forvalues		c=1/8 {
replace			c`c'="" in 1
replace			c`c'="" in 7
}
foreach			c in 1 3 5 7 {
forvalues		r=4/5 {
replace			c`c'="" in `r'
}
}
foreach			c in 2 4 6 8 {
forvalues		r=8/10 {
replace			c`c'="" in `r'
}
}
forvalues		s=1/12 {
g				s`s'="&"
}
g				l="\\"
foreach			r in 1 3 5 6 7 9 {
replace			l="\\\\" in `r'
}
order			c11 s11 c1 s1 c2 s2 s3 c3 s4 c4 s5 s6 c5 s7 c6 s8 s9 c7 s10 c8 l
browse			c11 s11 c1 s1 c2 s2 s3 c3 s4 c4 s5 s6 c5 s7 c6 s8 s9 c7 s10 c8 l

